package com.project.service.impl;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserDao userDao;

    @Override
    public UserBean login(String userName, String pwd) {
        return userDao.login(userName, pwd);
    }

    @Override
    public boolean addUser(UserBean user) {
        boolean flag = userDao.checkName(user.getName());
        if (flag) {
            userDao.addUser(user);
        }
        return flag;
    }

    @Override
    public boolean checkName(String userName) {

        return userDao.checkName(userName);
    }

    @Override
    public List<UserBean> findAll() {

        return userDao.findAll();
    }

    @Override
    public boolean delUser(int id, UserBean loginUser) {
        if (id == loginUser.getId()) {
            return false;
        } else {
            userDao.delUser(id);
            return true;
        }
    }

    @Override
    public UserBean findById(int id) {
        return userDao.findById(id);
    }

    @Override
    public void updateUserLevel(int id, String level) {
        userDao.updateUserLevel(id, level);

    }

    @Override
    public void updateUserPwd(int id, String pwd) {
        userDao.updateUserPwd(id, pwd);
    }

}
